package com.mrd.gtimp.business.entity;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Transient;
import javax.validation.Valid;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import com.mrd.annotation.freemarker.MRDFreeMarkerCustomFields;
import com.mrd.annotation.validation.InDeclarationRequiredGroup;
import com.mrd.annotation.validation.MRDLength;
import com.mrd.annotation.validation.MRDRequired;
import com.mrd.annotation.validation.OutDeclarationRequiredGroup;
import com.mrd.evaluate.entity.Evaluation;
import com.mrd.gtimp.base.entity.User;
import com.mrd.gtimp.order.entity.DeclaContainer;
import com.mrd.util.PkCleanerUtil;
import com.mrd.util.PkConfig;

/**
 * <p>
 * application name: sample
 * <p>
 * copyright: Copyright@2012 明睿达科技有限公司
 */

/**
 * 报关信息
 *
 * @author winaya
 */
@Entity(name = "T_BIZ_DECLARATION")
@MRDFreeMarkerCustomFields(customClassFields = {"declaContainers", "commodities", "suiFuDans",
        "declarationInform", "contractTerms"}, superCustomFields = {"supCompany", "shipper"})
public class Declaration extends BaseBusiness implements Serializable {
    public String getTempAttachmentBillNo() {
        return tempAttachmentBillNo;
    }

    public void setTempAttachmentBillNo(String tempAttachmentBillNo) {
        this.tempAttachmentBillNo = tempAttachmentBillNo;
    }

    /**
     * 报关业务状态
     */
    public static class DeclarationBusinessState {
        /**
         * 草稿状态
         */
        public static final String DRAFT_STATE = "DS00";
        /**
         * 用户提交，已下单，待审核
         */
        public static final String ORDER_STATE = "DS01";
        /**
         * 平台审核通过
         */
        public static final String PASS_STATE = "DS02";
        /**
         * 驳回状态
         */
        public static final String REJECT_STATE = "DS03";
        /**
         * 驳回等待客户修改提交状态
         */
        public static final String REJECT_WAIT_REDIT_STATE = "DS030";
        /**
         * 已受理状态,佛港专用状态
         */
        public static final String ACCEPT_STATE = "DS04";
        /**
         * 已完成状态
         */
        public static final String COMPLETE_STATE = "DS05";
        /**
         * 初审,佛港专用状态
         */
        public static final String FIR_PASS = "DS06";
        /**
         * 复审,佛港专用状态
         */
        public static final String SEC_PAS = "DS07";
        /**
         * 现场提交,佛港专用状态
         */
        public static final String SCENE_SUBMIT = "DS08";
        /**
         * 海关查货
         */
        public static final String CUSTOM_CHECK = "DS09";
        /**
         * 海关放行
         */
        public static final String CUSTOM_PASS = "DS10";
        /**
         * 商检放行
         */
        public static final String COMMODITY_PASS = "DS11";
        /**
         * 海关退单
         */
        public static final String CUSTOM_CHARGEBACK = "DS13";

        /**
         * 查验状态
         */
        public static final String VERIFY_ING = "DS120";// 查验中
        public static final String VERIFY_DOME = "DS121";// 查验完成
        public static final String VERIFY_FAIL = "DS122";// 查验不通过
        public static final String VERIFY_CT_PASS = "DS124";// 海关放行
        public static final String VERIFY_SJ_PASS = "DS125";// 商检放行
        public static final String VERIFY_OT_PASS = "DS126";// 其他放行

        public static String cnString(String state){
            String cnStr = "";
            if(state == null){
                return cnStr;
            }
            switch (state){
                case DRAFT_STATE:
                    cnStr = "草稿";
                    break;
                case ORDER_STATE:
                    cnStr = "已提交";
                    break;
                case PASS_STATE:
                    cnStr = "已受理";
                    break;
                case REJECT_STATE:
                    cnStr = "已驳回";
                    break;
                case REJECT_WAIT_REDIT_STATE:
                    cnStr = "驳回（待处理）";
                    break;
                case ACCEPT_STATE:
                    cnStr = "已受理";
                    break;
                case COMPLETE_STATE:
                    cnStr = "已完成";
                    break;
                case FIR_PASS:
                    cnStr = "初审";
                    break;
                case SEC_PAS:
                    cnStr = "复审";
                    break;
                case SCENE_SUBMIT:
                    cnStr = "现场提交";
                    break;
                case CUSTOM_CHECK:
                    cnStr = "海关查货";
                    break;
                case CUSTOM_PASS:
                    cnStr = "海关放行";
                    break;
                case COMMODITY_PASS:
                    cnStr = "商检放行";
                    break;
                case CUSTOM_CHARGEBACK:
                    cnStr = "海关退单";
                    break;
                case VERIFY_ING:
                    cnStr = "查验中";
                    break;
                case VERIFY_DOME:
                    cnStr = "查验完成";
                    break;
                case VERIFY_FAIL:
                    cnStr = "查验不通过";
                    break;
                case VERIFY_CT_PASS:
                    cnStr = "海关放行";
                    break;
                case VERIFY_SJ_PASS:
                    cnStr = "商检放行";
                    break;
                case VERIFY_OT_PASS:
                    cnStr = "其他放行";
                default:

            }
            return cnStr;
        }
    }

    /**
     * 进口类型
     */
    public static final String DECLARATION_TYPE_ENTRY = "I";
    /**
     * 出口类型
     */
    public static final String DECLARATION_TYPE_EXPORT = "E";
    /**
     * 一般贸易
     */
    public static final String TRADE_TYPE_GENERAL = "0";
    /**
     * 加工贸易
     */
    public static final String TRADE_TYPE_Process = "1";
    /**
     * 特殊贸易
     */
    public static final String TRADE_TYPE_Special = "2";

    private static final long serialVersionUID = 279388318437971086L;

    // ------------------------------------------ 3.0 gtimp
    /**
     * 统一编号
     */
    @MRDLength(max = 225, name = "统一编号")
    @Column(name = "UNITYNO_")
    private String unityNo;

    /**
     * 申报状态
     */
    @MRDLength(max = 3, name = "申报状态")
    @Column(name = "DECLARE_STATE_")
    private String declareState;

    /**
     * 集装箱信息表
     */
    @Valid
    @OneToMany(mappedBy = "declaration", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<DeclaContainer> declaContainers;

    /**
     * 经营单位编号（收发货人）
     */
    @MRDLength(max = 200, name = "经营单位编号（收发货人）")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "收发货人")
    @Column(name = "COMPANY_CO")
    private String company_co;

    /**
     * 经营单位编号18位社会统一代码
     */
    @MRDLength(max = 20, name = "经营单位编号")
    @Column(name = "COMPANY_CO_UNITE")
    private String company_co_unite;

    /**
     * 经营单位名称
     */
    @MRDLength(max = 100, name = "经营单位名称")
    @Column(name = "COMPANY_NAME")
    private String company_name;

    /**
     * 转关提前报关
     */
    @MRDLength(max = 2, name = "转关提前报关")
    @Column(name = "DECLAR_UP_")
    private String declarUp;

    // ------------------------------------------- 2.0 gtimp

    /**
     * 预录入编号,报关单号
     */
    @MRDLength(max = 18, name = "报关单号")
    @Column(name = "SNO")
    private String sno;

    /**
     * 业务类型 业务类型的值有：MCC、转关等
     */
    private String data_type;

    /**
     * 船舶代码（海关监督簿号）
     */
    @Column(name = "SHIP_CODE")
    private String ship_code;

    /**
     * 提单号
     */
    @MRDLength(max = 50, name = "提运单号")
    @Column(name = "BL_NO")
    private String bl_no;

    /**
     * 运输工具名称
     */
    @MRDLength(max = 50, name = "运输工具名称")
    @Column(name = "TRANSPORT_NA")
    private String transport_na;

    /**
     * 申报单位编码
     */
    @MRDLength(max = 20, name = "申报单位编码")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "申报单位")
    @Column(name = "SHENBAO_COMPANY_CO")
    private String shenbao_company_co;

    /**
     * 申报单位编号18位社会统一代码
     */
    @MRDLength(max = 20, name = "申报单位编号")
    @Column(name = "SHENBAO_COMPANY_CO_UNITE")
    private String shenbao_company_co_unite;

    /**
     * 申报单位名称
     */
    @MRDLength(max = 100, name = "申报单位名称")
    @Column(name = "SHENBAO_COMPANY_NAME")
    private String shenbao_company_name;

    /**
     * 航次号
     */
    @MRDLength(max = 50, name = "航次号")
    @Column(name = "VOYAGE_NO")
    private String voyage_no;
    /**
     * 运抵国/启运国
     */
    @MRDLength(max = 100, name = "运抵国/启运国")
    @Column(name = "ARRIVED_COUNTRY")
    private String arrived_country;
    /**
     * 运抵国代码
     */
    @MRDLength(max = 10, name = "运抵国代码")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "运抵国/启运国")
    @Column(name = "ARRIVED_COUNTRY_CODE")
    private String arrived_country_code;
    /**
     * 指运港
     */
    @MRDLength(max = 50, name = "指运港")
    @Column(name = "ARRIVED_PORT")
    private String arrived_port;
    /**
     * 指运港代码
     */
    @MRDLength(max = 10, name = "指运港代码")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "指运港/装货港")
    @Column(name = "ARRIVED_PORT_CODE")
    private String arrived_port_code;
    /**
     * 境内货源地
     */
    @MRDLength(max = 50, name = "境内货源地")
    // @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
    // name = "境内货源地")
    @Column(name = "GOODS_ADDR")
    private String goods_addr;
    /**
     * 境内货源地代码
     */
    @MRDLength(max = 20, name = "境内货源地代码")
    // @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
    // name = "境内货源地、境内目的地")
    @Column(name = "GOODS_ADDR_CODE")
    private String goods_addr_code;
    /**
     * 其他货源地
     */
    @MRDLength(max = 50, name = "其他货源地")
    @Column(name = "OTHER_GOODS_ADDR")
    private String other_goods_addr;
    /**
     * 批准文号
     */
    @MRDLength(max = 50, name = "批准文号")
    @Column(name = "APPROVAL_NO")
    private String approval_no;
    /**
     * 成交方式
     */
    @MRDLength(max = 20, name = "成交方式")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "成交方式")
    @Column(name = "DEAL_MODE")
    private String deal_mode;
    /**
     * 件数
     */
    @MRDLength(max = 20, name = "件数")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "件数")
    @Column(name = "GOODS_COUNT")
    private String goods_count;
    /**
     * 包装种类
     */
    @MRDLength(max = 20, name = "包装种类")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "包装种类")
    @Column(name = "GOODS_PACKAGE")
    private String goods_package;

    /**
     * 净重
     */
    @MRDLength(max = 20, name = "净重")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "净重")
    @Column(name = "NET_WEIGHT")
    private String net_weight;
    /**
     * 备注
     */
    @MRDLength(max = 1000, name = "备注")
    @Column(name = "REMARK")
    private String remark;
    /**
     * 贸易方式/监管方式
     */
    @MRDLength(max = 20, name = "贸易方式/监管方式")
    @Column(name = "TRADE_MODE")
    private String trade_mode;
    /**
     * 贸易方式/监管方式代码
     */
    @MRDLength(max = 15, name = "贸易方式/监管方式代码")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "监管方式")
    @Column(name = "TRADE_MODE_CODE")
    private String trade_mode_code;
    /**
     * 运输方式
     */
    @MRDLength(max = 50, name = "运输方式")
    // @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
    // name = "运输方式")
    @Column(name = "TRANSPORT_MODE")
    private String transport_mode;
    /**
     * 运输方式编码
     */
    @MRDLength(max = 10, name = "运输运输方式编码")
    @Column(name = "TRANSPORT_MODE_CODE_")
    private String transport_mode_code;
    /**
     * 发货单位编号（生产销售单位，消费使用单位）
     */
    @MRDLength(max = 200, name = "发货单位编号（生产销售单位，消费使用单位）")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "生产销售单位，消费使用单位")
    @Column(name = "FAHUO_COMPANY_CO")
    private String fahuo_company_co;

    /**
     * 发货单位编号18位社会统一代码
     */
    @MRDLength(max = 20, name = "发货单位编号")
    @Column(name = "FAHUO_COMPANY_CO_UNITE")
    private String fahuo_company_co_unite;

    /**
     * 发货单位名称
     */
    @MRDLength(max = 100, name = "发货单位名称")
    @Column(name = "FAHUO_COMPANY_NAME")
    private String fahuo_company_name;
    /**
     * 征免性质
     */
    @MRDLength(max = 100, name = "征免性质")
    @Column(name = "LEVYMODE")
    private String levymode;
    /**
     * 征免性质代码
     */
    @MRDLength(max = 20, name = "征免性质代码")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "征免性质")
    @Column(name = "LEVYMODE_CODE")
    private String levymode_code;
    /**
     * 结汇方式
     */
    @MRDLength(max = 10, name = "结汇方式")
    @Column(name = "LC_TYPE")
    private String lc_type;
    /**
     * 合同协议号
     */
    @MRDLength(max = 100, name = "合同协议号")
    @Column(name = "CONTRACT_NO")
    private String contract_no;
    /**
     * 毛重
     */
    @MRDLength(max = 20, name = "毛重")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "毛重")
    @Column(name = "GROSS_WEIGHT")
    private String gross_weight;
    /**
     * 报关单类型
     */
    @MRDLength(max = 10, name = "报关单类型")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "报关单类型")
    @Column(name = "CUSTOMS_TYPE")
    private String customs_type;

    /**
     * 备案号
     */
    @MRDLength(max = 20, name = "备案号")
    @Column(name = "RECORD_ID")
    private String record_id;
    /**
     * 出口日期/进口日期
     */
    @Column(name = "EXPORT_DATE")
    private Date export_date;
    /**
     * 申报日期
     */
    @Column(name = "REPORT_DATE")
    private Date report_date;
    /**
     * 生产厂家
     */
    @MRDLength(max = 100, name = "生产厂家")
    @Column(name = "PRODUCE_FACTORY")
    private String produce_factory;
    /**
     * 运费计费方式
     */
    @MRDLength(max = 10, name = "运费计费方式")
    @Column(name = "FREIGHT1")
    private String freight1;
    /**
     * 运费计算方式编码 没有存入数据库
     */
    @Transient
    private String freight1Code;
    /**
     * 运费数量
     */
    @MRDLength(max = 10, name = "运费数量")
    @Column(name = "FREIGHT2")
    private String freight2;
    /**
     * 运费币制
     */
    @MRDLength(max = 10, name = "运费币制")
    @Column(name = "FREIGHT3")
    private String freight3;
    /**
     * 运费币制编码 没有存入数据库
     */
    @Transient
    private String freight3Code;
    /**
     * 保费计费方式
     */
    @MRDLength(max = 10, name = "保费计费方式")
    @Column(name = "PREMIUM1")
    private String premium1;
    /**
     * 保费计费方式编码 没有存入数据库
     */
    @Transient
    private String premium1Code;
    /**
     * 保费数量
     */
    @MRDLength(max = 10, name = "保费数量")
    @Column(name = "PREMIUM2")
    private String premium2;
    /**
     * 保费币制
     */
    @MRDLength(max = 10, name = "保费币制")
    @Column(name = "PREMIUM3")
    private String premium3;
    /**
     * 保费币制编码 没有存入数据库
     */
    @Transient
    private String premium3Code;
    /**
     * 杂费计费方式
     */
    @MRDLength(max = 10, name = "杂费计费方式")
    @Column(name = "OTHERFEE1")
    private String otherfee1;
    /**
     * 杂费计费方式编码 没有存入数据库
     */
    @Transient
    private String otherfee1Code;
    /**
     * 杂费数量
     */
    @MRDLength(max = 10, name = "杂费数量")
    @Column(name = "OTHERFEE2")
    private String otherfee2;
    /**
     * 杂费币制
     */
    @MRDLength(max = 10, name = "杂费币制")
    @Column(name = "OTHERFEE3")
    private String otherfee3;
    /**
     * 杂费币制编码 没有存入数据库
     */
    @Transient
    private String otherfee3Code;
    /**
     * 关联报关单
     */
    @MRDLength(max = 50, name = "关联报关单")
    @Column(name = "RE_MANIFEST")
    private String re_manifest;
    /**
     * 关联备案
     */
    @MRDLength(max = 50, name = "关联备案")
    @Column(name = "RE_RECORD_ID")
    private String re_record_id;
    /**
     * 监管仓号
     */
    @MRDLength(max = 50, name = "监管仓号")
    @Column(name = "RE_JIANGUAN")
    private String re_jianguan;
    /**
     * 货场代码
     */
    @MRDLength(max = 50, name = "货场代码")
    @Column(name = "RE_YARD_ID")
    private String re_yard_id;
    /**
     * 出口口岸 / 进口口岸
     */
    @MRDLength(max = 20, name = "出口口岸 / 进口口岸")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "出口口岸/进口口岸")
    @Column(name = "EXPORT_PORT")
    private String export_port;

    /**
     * 出口口岸代码 / 进口口岸代码
     */
    @MRDLength(max = 15, name = "出口口岸代码 / 进口口岸代码")
    @Column(name = "EXPORT_PORT_CODE")
    private String export_port_code;
    /**
     * 纳税单位
     */
    @MRDLength(max = 50, name = "纳税单位")
    // @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
    // name = "纳税单位")
    @Column(name = "TEX_COMPANY")
    private String tex_company;
    /**
     * 许可证号
     */
    @MRDLength(max = 20, name = "许可证号")
    @Column(name = "LICENSE_NO")
    private String license_no;
    /**
     * 随附单证
     */
    @MRDLength(max = 80, name = "随附单证")
    @Column(name = "SUIFUDAN")
    private String suifudan;
    @Transient
    private String suifudanValue;
    /**
     * 船名
     */
    @MRDLength(max = 20, name = "船名")
    @Column(name = "SHIP_NAME")
    private String ship_name;
    /**
     * 报关报检业务状态
     */
    @MRDLength(max = 10, name = "报关报检业务状态")
    @Column(name = "STATE")
    private String state;

    /**
     * 商品信息
     */
    @Valid
    @OneToMany(mappedBy = "declaration", cascade = CascadeType.ALL, orphanRemoval = true)
    @OrderBy("index_num asc")
    private List<Commodity> commodities;


    /**
     * 随附单信息
     */
    @Valid
    @OneToMany(mappedBy = "declaration", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<SuiFuDan> suiFuDans;
    @OneToOne(mappedBy = "declaration")
    private DeclarationInform declarationInform;
    @OneToOne(mappedBy = "declaration")
    private ContractTerms contractTerms;

    /**
     * 卖家
     */
    @MRDLength(max = 100, name = "卖家")
    @Column(name = "SELLER")
    private String seller;

    /**
     * 卖家地址
     */
    @MRDLength(max = 200, name = "卖家地址")
    @Column(name = "SELLER_ADDRESS")
    private String seller_address;

    /**
     * 卖家电话
     */
    @MRDLength(max = 50, name = "卖家电话")
    @Column(name = "SELLER_PHONE")
    private String seller_phone;

    /**
     * 卖家传真
     */
    @MRDLength(max = 20, name = "卖家传真")
    @Column(name = "SELLER_FAX")
    private String seller_fax;

    /**
     * 箱唛
     */
    @MRDLength(max = 500, name = "箱唛")
    @Column(name = "CARTON")
    private String carton;

    /**
     * 买方
     */
    @MRDLength(max = 100, name = "买方")
    @Column(name = "BUYER")
    private String buyer;

    /**
     * 发票号
     */
    @MRDLength(max = 100, name = "发票号")
    @Column(name = "INVOICE_NO")
    private String invoice_no;

    /**
     * 有无木质包装
     */
    @MRDLength(max = 2, name = "有无木质包装")
    @Column(name = "IS_WOOD_PACKAGING")
    private String is_wood_packaging;

    /**
     * 合同备注
     */
    @MRDLength(max = 1500, name = "合同备注")
    @Column(name = "CONTRACT_REMARK")
    private String contract_remark;

    /**
     * 货物总金额
     */
    @MRDLength(max = 20, name = "货物总金额")
    @Column(name = "TOTAL_MONEY")
    private String total_money;

    /**
     * 总计价数量
     */
    @MRDLength(max = 20, name = "总计价数量")
    @Column(name = "SUM_COUNT")
    private String sum_count;

    /**
     * 签约日期
     */
    @Column(name = "CONTRACT_DATE")
    private Date contract_date;

    /**
     * 制单日期
     */
    @Column(name = "MAKING_DATE")
    private Date making_date;

    /**
     * 签约地点
     */
    @MRDLength(max = 100, name = "签约地点")
    @Column(name = "SINGING_PLACE")
    private String singing_place;

    /**
     * 具体包装种类
     */
    @MRDLength(max = 50, name = "具体包装种类")
    @Column(name = "CONCRETE_GOODS_PACKAGE")
    private String concrete_goods_package;

    /**
     * 是否为手册报关单
     */
    @MRDLength(max = 3, name = "是否为手册报关单")
    @Column(name = "IS_RECORD_INFO")
    private String is_record_info;

    /**
     * 是否是合同条款模板
     */
    @MRDLength(max = 2, name = "CONTRACT_TERMS_TYPE")
    @Column(name = "CONTRACT_TERMS_TYPE")
    private String contract_terms_type;

    /**
     * 申报口岸(申报地海关)
     */
    @MRDLength(max = 20, name = "申报口岸(申报地海关)")
    // @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
    // name = "申报地海关")
    @Column(name = "DECLARATION_PORT")
    private String declaration_port;

    /**
     * 申报口岸代码（申报地海关代码）
     */
    @MRDLength(max = 20, name = "申报口岸代码（申报地海关代码）")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "申报地海关")
    @Column(name = "DECLARATION_PORT_CODE")
    private String declaration_port_code;
    /**
     * 贸易国
     */
    @MRDLength(max = 20, name = "贸易国")
    @Column(name = "TRADING_COUNTRY")
    private String trading_country;
    /**
     * 贸易国代码
     */
    @MRDLength(max = 20, name = "贸易国代码")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "贸易国")
    @Column(name = "TRADING_COUNTRY_CODE")
    private String trading_country_code;
    /**
     * 特殊关系确认
     */
    @MRDLength(max = 20, name = "特殊关系确认")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "特殊关系确认")
    @Column(name = "SPECIAL_RELATIONSHIP_CONFIRM")
    private String special_relationship_confirm;
    /**
     * 价格影响确认
     */
    @MRDLength(max = 20, name = "价格影响确认")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "价格影响确认")
    @Column(name = "PRICE_IMPACT_CONFIRM")
    private String price_impact_confirm;
    /**
     * 支付特许权使用费确认
     */
    @MRDLength(max = 20, name = "支付特许权使用费确认")
    @MRDRequired(groups = {InDeclarationRequiredGroup.class, OutDeclarationRequiredGroup.class},
            name = "支付特许权使用费确认")
    @Column(name = "PAYMENT_ROYALTILS_CONFIRM")
    private String payment_royaltils_confirm;
    /**
     * 以下信息为反馈信息
     */
    /**
     * 海关放行时间
     */
    @Column(name = "CUSTOM_TIME")
    private Date custom_time;
    /**
     * 海关放行信息(报关状态)
     */
    @MRDLength(max = 10, name = "海关放行信息(报关状态)")
    @Column(name = "CUSTOM_STATUS")
    private String custom_status;
    /**
     * 商检放行时间
     */
    @Column(name = "CHECK_TIME")
    private Date check_time;
    /**
     * 商检放行信息(报检状态)
     */
    @MRDLength(max = 10, name = "商检放行信息(报检状态)")
    @Column(name = "CHECK_STATUS")
    private String check_status;
    /**
     * 存放分柜资料的文件
     */
    @OneToOne
    @JoinColumn(name = "CONTAINERINFO_FILE_ID")
    private Attachment containerInfo;

    /**
     * 3.0存放底单上载资料文件
     */
    @OneToMany(mappedBy = "declaration")
    private List<DiDanAttachment> diDans;

    /**
     * 存放底单上载资料文件
     */
    @OneToOne
    @JoinColumn(name = "DIDAN_FILE_ID")
    private Attachment uploadDiDan;

    /**
     * 集装箱号
     */
    @MRDLength(max = 2000, name = "集装箱号")
    @Column(name = "CONTAINER_NO")
    private String container_no;

    /**
     * 显示的集装箱号
     */
    @MRDLength(max = 4000, name = "显示的集装箱号")
    @Column(name = "CONTAINER_NO_SHOW")
    private String container_no_show;

    /**
     * SO号
     */
    @MRDLength(max = 50, name = "SO号")
    @Column(name = "SO")
    private String so;

    /**
     * 适用的收费项目
     */
    @Transient
    private DeclarationFreeDetail declarationFreeDetail;
    /**
     * 支付信息
     */
    @Transient
    private DeclarationFree declarationFree;
    /**
     * 报关费用(不含报检,熏蒸)
     */
    @Transient
    private Double declaration_free;

    /**
     * 货柜数量
     */
    @Column(name = "CONTAINER_NUM")
    private String container_num;

    /**
     * 交易id
     */
    @Transient
    private String pay_id;

    /**
     * 三联单号
     */
    @MRDLength(max = 20, name = "三联单号")
    @Column(name = "WORK_NO")
    private String workNo;

    /**
     * 付款类型 0:未付款 1:已付款 2:免费
     */
    @MRDLength(max = 4, name = "付款类型")
    @Column(name = "payment_type")
    private String payment_type;

    /**
     * 报关单进出口类型，E出口，I进口
     */
    @MRDLength(max = 1, name = "报关单进出口类型")
    @Column(name = "DECLARATION_TYPE")
    private String declaration_type;

    /**
     * 贸易类型 0一般贸易，1加工贸易，2特殊贸易
     */
    @Column(name = "TRADE_TYPE_")
    private String tradeType;

    @Transient
    private Evaluation evaluation;
    /**
     * 查验商品
     */
    @OneToMany(mappedBy = "declaration", cascade = CascadeType.ALL)
    private List<InspectionGoods> inspectionGoodsList;

    /**
     * 客户支付时间
     */
    @Column(name = "PAYMENT_TIME")
    private Date paymentTime;

    /**
     * 记录客户的复制、使用模板、暂存、提交的动作 格式如：M3-s3-s3-s3-S3 或 s2-S2 或C3-S3-S3或E3-S3 C：复制，s:保存，S：提交，
     * M：使用模板，E：excl导入，2：2.0页面,3：3.0页面 被驳回的单可能会出现SS相接的情况
     */
    @Column(name = "action_chain")
    private String actionChain;

    /**
     * 锁定状态 0：解锁，1：锁定
     */
    @Column(name = "LOCK_STATUS")
    private String lockStatus;

    @Transient
    private String tempAttachmentBillNo;
    @Transient
    private RejectContent rejectContent;

    @Transient
    private String declaStatus;
    /**
     * 商品项数
     */
    @Column(name = "GOODS_ITEM_NUM")
    private String goods_item_num;

    /**
     * 确认三联单状态，0：未确认，1-已确认
     */
    @Column(name = "CONFIRM_TYPE")
    private String confirmType;

    /**
     * 确认三联单时间
     */
    @Column(name = "CONFIRM_TYPE_TIME")
    private Date confirmTypeTime;


    // ===========一线通5.0===================
    /**
     * 5.0查验跟踪
     */
    @OneToMany(mappedBy = "declaration", cascade = CascadeType.ALL)
    private List<DeclaCheckTracking> declaCheckTracking;


    public List<DeclaCheckTracking> getDeclaCheckTracking() {
        return declaCheckTracking;
    }

    public void setDeclaCheckTracking(List<DeclaCheckTracking> declaCheckTracking) {
        this.declaCheckTracking = declaCheckTracking;
    }

    public List<InspectionGoods> getInspectionGoodsList() {
        return inspectionGoodsList;
    }

    public void setInspectionGoodsList(List<InspectionGoods> inspectionGoodsList) {
        this.inspectionGoodsList = inspectionGoodsList;
    }

    public String getDeclaration_type() {
        return declaration_type;
    }

    public void setDeclaration_type(String declaration_type) {
        this.declaration_type = declaration_type;
    }

    public List<Commodity> getCommodities() {
        return commodities;
    }

    public void setCommodities(List<Commodity> commodities) {
        this.commodities = commodities;
    }

    public Evaluation getEvaluation() {
        return evaluation;
    }

    public void setEvaluation(Evaluation evaluation) {
        this.evaluation = evaluation;
    }

    /**
     * 构造方法，通过字符串转换
     */
    public Declaration(String declarationString) {
        fromString(declarationString);
    }

    public Declaration() {
        super();
    }

    public String getSno() {
        return sno;
    }

    public void setSno(String sno) {
        this.sno = sno;
    }

    public String getBl_no() {
        return bl_no;
    }

    public void setBl_no(String bl_no) {
        this.bl_no = bl_no;
    }

    public String getCompany_co() {
        return company_co;
    }

    public void setCompany_co(String company_co) {
        this.company_co = company_co;
    }

    public String getFahuo_company_co() {
        return fahuo_company_co;
    }

    public void setFahuo_company_co(String fahuo_company_co) {
        this.fahuo_company_co = fahuo_company_co;
    }

    public String getTransport_na() {
        return transport_na;
    }

    public void setTransport_na(String transport_na) {
        this.transport_na = transport_na;
    }

    public String getVoyage_no() {
        return voyage_no;
    }

    public void setVoyage_no(String voyage_no) {
        this.voyage_no = voyage_no;
    }

    public String getArrived_country() {
        return arrived_country;
    }

    public void setArrived_country(String arrived_country) {
        this.arrived_country = arrived_country;
    }

    public String getDeclarUp() {
        return declarUp;
    }

    public void setDeclarUp(String declarUp) {
        this.declarUp = declarUp;
    }

    public String getArrived_port() {
        return arrived_port;
    }

    public void setArrived_port(String arrived_port) {
        this.arrived_port = arrived_port;
    }

    public String getGoods_addr() {
        return goods_addr;
    }

    public void setGoods_addr(String goods_addr) {
        this.goods_addr = goods_addr;
    }

    public String getApproval_no() {
        return approval_no;
    }

    public void setApproval_no(String approval_no) {
        this.approval_no = approval_no;
    }

    public String getDeal_mode() {
        return deal_mode;
    }

    public void setDeal_mode(String deal_mode) {
        this.deal_mode = deal_mode;
    }

    public String getGoods_count() {
        return goods_count;
    }

    public void setGoods_count(String goods_count) {
        this.goods_count = goods_count;
    }

    public String getGoods_package() {
        return goods_package;
    }

    public void setGoods_package(String goods_package) {
        this.goods_package = goods_package;
    }

    public String getNet_weight() {
        return net_weight;
    }

    public void setNet_weight(String net_weight) {
        this.net_weight = net_weight;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getTrade_mode() {
        return trade_mode;
    }

    public void setTrade_mode(String trade_mode) {
        this.trade_mode = trade_mode;
    }

    public String getTrade_mode_code() {
        return trade_mode_code;
    }

    public void setTrade_mode_code(String trade_mode_code) {
        this.trade_mode_code = trade_mode_code;
    }

    public String getCompany_name() {
        return company_name;
    }

    public void setCompany_name(String company_name) {
        this.company_name = company_name;
    }

    public String getTransport_mode() {
        return transport_mode;
    }

    public void setTransport_mode(String transport_mode) {
        this.transport_mode = transport_mode;
    }

    public String getFahuo_company_name() {
        return fahuo_company_name;
    }

    public void setFahuo_company_name(String fahuo_company_name) {
        this.fahuo_company_name = fahuo_company_name;
    }

    public String getLevymode() {
        return levymode;
    }

    public void setLevymode(String levymode) {
        this.levymode = levymode;
    }

    public String getLc_type() {
        return lc_type;
    }

    public void setLc_type(String lc_type) {
        this.lc_type = lc_type;
    }

    public String getContract_no() {
        return contract_no;
    }

    public void setContract_no(String contract_no) {
        this.contract_no = contract_no;
    }

    public String getGross_weight() {
        return gross_weight;
    }

    public void setGross_weight(String gross_weight) {
        this.gross_weight = gross_weight;
    }

    public String getCustoms_type() {
        return customs_type;
    }

    public void setCustoms_type(String customs_type) {
        this.customs_type = customs_type;
    }

    public String getRecord_id() {
        return record_id;
    }

    public void setRecord_id(String record_id) {
        this.record_id = record_id;
    }

    public Date getExport_date() {
        return export_date;
    }

    public void setExport_date(Date export_date) {
        this.export_date = export_date;
    }

    public String getShenbao_company_co() {
        return shenbao_company_co;
    }

    public void setShenbao_company_co(String shenbao_company_co) {
        this.shenbao_company_co = shenbao_company_co;
    }

    public String getShenbao_company_name() {
        return shenbao_company_name;
    }

    public void setShenbao_company_name(String shenbao_company_name) {
        this.shenbao_company_name = shenbao_company_name;
    }

    public String getFreight1() {
        return freight1;
    }

    public void setFreight1(String freight1) {
        this.freight1 = freight1;
    }

    public String getFreight2() {
        return freight2;
    }

    public void setFreight2(String freight2) {
        this.freight2 = freight2;
    }

    public String getFreight3() {
        return freight3;
    }

    public void setFreight3(String freight3) {
        this.freight3 = freight3;
    }

    public String getPremium1() {
        return premium1;
    }

    public void setPremium1(String premium1) {
        this.premium1 = premium1;
    }

    public String getPremium2() {
        return premium2;
    }

    public void setPremium2(String premium2) {
        this.premium2 = premium2;
    }

    public String getPremium3() {
        return premium3;
    }

    public void setPremium3(String premium3) {
        this.premium3 = premium3;
    }

    public String getOtherfee1() {
        return otherfee1;
    }

    public void setOtherfee1(String otherfee1) {
        this.otherfee1 = otherfee1;
    }

    public String getOtherfee2() {
        return otherfee2;
    }

    public void setOtherfee2(String otherfee2) {
        this.otherfee2 = otherfee2;
    }

    public String getOtherfee3() {
        return otherfee3;
    }

    public void setOtherfee3(String otherfee3) {
        this.otherfee3 = otherfee3;
    }

    public String getRe_manifest() {
        return re_manifest;
    }

    public void setRe_manifest(String re_manifest) {
        this.re_manifest = re_manifest;
    }

    public String getRe_record_id() {
        return re_record_id;
    }

    public void setRe_record_id(String re_record_id) {
        this.re_record_id = re_record_id;
    }

    public String getRe_jianguan() {
        return re_jianguan;
    }

    public void setRe_jianguan(String re_jianguan) {
        this.re_jianguan = re_jianguan;
    }

    public String getRe_yard_id() {
        return re_yard_id;
    }

    public void setRe_yard_id(String re_yard_id) {
        this.re_yard_id = re_yard_id;
    }

    public String getExport_port() {
        return export_port;
    }

    public void setExport_port(String export_port) {
        this.export_port = export_port;
    }

    public String getExport_port_code() {
        return export_port_code;
    }

    public void setExport_port_code(String export_port_code) {
        this.export_port_code = export_port_code;
    }

    public String getTex_company() {
        return tex_company;
    }

    public void setTex_company(String tex_company) {
        this.tex_company = tex_company;
    }

    public String getLicense_no() {
        return license_no;
    }

    public void setLicense_no(String license_no) {
        this.license_no = license_no;
    }

    public String getSuifudan() {
        return suifudan;
    }

    public void setSuifudan(String suifudan) {
        this.suifudan = suifudan;
    }

    public String getShip_name() {
        return ship_name;
    }

    public void setShip_name(String ship_name) {
        this.ship_name = ship_name;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public List<SuiFuDan> getSuiFuDans() {
        return suiFuDans;
    }

    public void setSuiFuDans(List<SuiFuDan> suiFuDans) {
        this.suiFuDans = suiFuDans;
    }

    public void setDecState(String state) {
        setState(state);
    }

    public Object getDecState() {
        return getState();
    }

    public DeclarationInform getDeclarationInform() {
        return declarationInform;
    }

    public void setDeclarationInform(DeclarationInform declarationInform) {
        this.declarationInform = declarationInform;
    }

    public Date getCustom_time() {
        return custom_time;
    }

    public void setCustom_time(Date custom_time) {
        this.custom_time = custom_time;
    }

    public String getCheck_status() {
        return check_status;
    }

    public void setCheck_status(String check_status) {
        this.check_status = check_status;
    }

    public Date getCheck_time() {
        return check_time;
    }

    public void setCheck_time(Date check_time) {
        this.check_time = check_time;
    }

    public String getCustom_status() {
        return custom_status;
    }

    public void setCustom_status(String custom_status) {
        this.custom_status = custom_status;
    }

    public Attachment getContainerInfo() {
        return containerInfo;
    }

    public void setContainerInfo(Attachment containerInfo) {
        this.containerInfo = containerInfo;
    }

    public Attachment getUploadDiDan() {
        return uploadDiDan;
    }

    public void setUploadDiDan(Attachment uploadDiDan) {
        this.uploadDiDan = uploadDiDan;
    }

    public Date getReport_date() {
        return report_date;
    }

    public void setReport_date(Date report_date) {
        this.report_date = report_date;
    }

    public String getProduce_factory() {
        return produce_factory;
    }

    public void setProduce_factory(String produce_factory) {
        this.produce_factory = produce_factory;
    }

    public String getContainer_no() {
        return container_no;
    }

    public void setContainer_no(String container_no) {
        this.container_no = container_no;
    }

    public String getContainer_no_show() {
        return container_no_show;
    }

    public void setContainer_no_show(String container_no_show) {
        this.container_no_show = container_no_show;
    }

    public String getSeller() {
        return seller;
    }

    public void setSeller(String seller) {
        this.seller = seller;
    }

    public String getSeller_address() {
        return seller_address;
    }

    public void setSeller_address(String seller_address) {
        this.seller_address = seller_address;
    }

    public String getSeller_phone() {
        return seller_phone;
    }

    public void setSeller_phone(String seller_phone) {
        this.seller_phone = seller_phone;
    }

    public String getSeller_fax() {
        return seller_fax;
    }

    public void setSeller_fax(String seller_fax) {
        this.seller_fax = seller_fax;
    }

    public String getCarton() {
        return carton;
    }

    public void setCarton(String carton) {
        this.carton = carton;
    }

    public String getBuyer() {
        return buyer;
    }

    public void setBuyer(String buyer) {
        this.buyer = buyer;
    }

    public String getInvoice_no() {
        return invoice_no;
    }

    public void setInvoice_no(String invoice_no) {
        this.invoice_no = invoice_no;
    }

    public String getIs_wood_packaging() {
        return is_wood_packaging;
    }

    public void setIs_wood_packaging(String is_wood_packaging) {
        this.is_wood_packaging = is_wood_packaging;
    }

    public String getContract_remark() {
        return contract_remark;
    }

    public void setContract_remark(String contract_remark) {
        this.contract_remark = contract_remark;
    }

    public String getTotal_money() {
        return total_money;
    }

    public void setTotal_money(String total_money) {
        this.total_money = total_money;
    }

    public String getSum_count() {
        return sum_count;
    }

    public void setSum_count(String sum_count) {
        this.sum_count = sum_count;
    }

    public Date getContract_date() {
        return contract_date;
    }

    public void setContract_date(Date contract_date) {
        this.contract_date = contract_date;
    }

    public Date getMaking_date() {
        return making_date;
    }

    public void setMaking_date(Date making_date) {
        this.making_date = making_date;
    }

    public String getSinging_place() {
        return singing_place;
    }

    public void setSinging_place(String singing_place) {
        this.singing_place = singing_place;
    }

    public String getConcrete_goods_package() {
        return concrete_goods_package;
    }

    public void setConcrete_goods_package(String concrete_goods_package) {
        this.concrete_goods_package = concrete_goods_package;
    }

    public String getIs_record_info() {
        return is_record_info;
    }

    public void setIs_record_info(String is_record_info) {
        this.is_record_info = is_record_info;
    }

    public ContractTerms getContractTerms() {
        return contractTerms;
    }

    public void setContractTerms(ContractTerms contractTerms) {
        this.contractTerms = contractTerms;
    }

    public String getContract_terms_type() {
        return contract_terms_type;
    }

    public void setContract_terms_type(String contract_terms_type) {
        this.contract_terms_type = contract_terms_type;
    }

    // getter/setter
    public String getUnityNo() {
        return unityNo;
    }

    public void setUnityNo(String unityNo) {
        this.unityNo = unityNo;
    }

    public String getDeclareState() {
        return declareState;
    }

    public void setDeclareState(String declareState) {
        this.declareState = declareState;
    }

    public List<DeclaContainer> getDeclaContainers() {
        return declaContainers;
    }

    public List<DeclaContainer> getSortedDeclaContainers() {
        if (CollectionUtils.isNotEmpty(this.declaContainers)) {
            this.declaContainers.sort((o1, o2) -> {
                if (o1 == null || o2 == null) {
                    return 0;
                }
                String no1 = o1.getContainerNo();
                String no2 = o2.getContainerNo();
                char[] c1Arr = no1.toCharArray();
                char[] c2Arr = no2.toCharArray();
                int size = c1Arr.length > c2Arr.length ? c2Arr.length : c1Arr.length;
                for (int i = 0; i < size; i++) {
                    char c1 = c1Arr[i];
                    char c2 = c2Arr[i];
                    if (c1 > c2) {
                        return 1;
                    } else if (c1 < c2) {
                        return -1;
                    }
                }
                return 0;
            });
        }
        return this.declaContainers;
    }

    public void setDeclaContainers(List<DeclaContainer> declaContainers) {
        this.declaContainers = declaContainers;
    }

    @Override
    public void clearPk() throws Exception {
        PkConfig[] configs = {new PkConfig("id", String.class), new PkConfig("CREATOR", String.class),
                new PkConfig("CTIME|O", Date.class), new PkConfig("MODIFIER", String.class),
                new PkConfig("MTIME|O", Date.class), new PkConfig("CONFIRM_TIME|O", Date.class),
                new PkConfig("VALIDATE_TIME|O", Date.class), new PkConfig("validator_ext", String.class),
                new PkConfig("validator|O", User.class), new PkConfig("upload_time|O", Date.class),
                new PkConfig("uploader_ext", String.class), new PkConfig("uploader|O", User.class),
                new PkConfig("finish_time|O", Date.class), new PkConfig("finisher_ext", String.class),
                new PkConfig("finisher|O", User.class), new PkConfig("state", String.class),
                new PkConfig("contractTerms|O", ContractTerms.class),
                new PkConfig("declarationInform|O", DeclarationInform.class)

        };
        PkCleanerUtil.clearPk(this, configs);
        for (Commodity c : commodities) {
            PkConfig[] cconfigs = {new PkConfig("id", String.class),

                    new PkConfig("declaration|O", Declaration.class)};
            PkCleanerUtil.clearPk(c, cconfigs);
        }

        for (SuiFuDan s : suiFuDans) {
            PkConfig[] cconfigs = {new PkConfig("id", String.class),

                    new PkConfig("declaration|O", Declaration.class)};
            PkCleanerUtil.clearPk(s, cconfigs);
        }
    }

    public String getSo() {
        return so;
    }

    public void setSo(String so) {
        this.so = so;
    }

    public String getWork_no() {
        return workNo;
    }

    public void setWork_no(String work_no) {
        this.workNo = work_no;
    }

    public String getWorkNo() {
        return workNo;
    }

    public void setWorkNo(String workNo) {
        this.workNo = workNo;
    }

    public String getOther_goods_addr() {
        return other_goods_addr;
    }

    public void setOther_goods_addr(String other_goods_addr) {
        this.other_goods_addr = other_goods_addr;
    }

    public String getDeclaration_port() {
        return declaration_port;
    }

    public void setDeclaration_port(String declaration_port) {
        this.declaration_port = declaration_port;
    }

    public String getDeclaration_port_code() {
        return declaration_port_code;
    }

    public void setDeclaration_port_code(String declaration_port_code) {
        this.declaration_port_code = declaration_port_code;
    }

    public DeclarationFreeDetail getDeclarationFreeDetail() {
        return declarationFreeDetail;
    }

    public void setDeclarationFreeDetail(DeclarationFreeDetail declarationFreeDetail) {
        this.declarationFreeDetail = declarationFreeDetail;
    }

    public String getContainer_num() {
        return container_num;
    }

    public void setContainer_num(String container_num) {
        this.container_num = container_num;
    }

    public Double getDeclaration_free() {
        return declaration_free;
    }

    public void setDeclaration_free(Double declaration_free) {
        this.declaration_free = declaration_free;
    }

    public String getPay_id() {
        return pay_id;
    }

    public void setPay_id(String pay_id) {
        this.pay_id = pay_id;
    }

    public String getLevymode_code() {
        return levymode_code;
    }

    public void setLevymode_code(String levymode_code) {
        this.levymode_code = levymode_code;
    }

    public String getGoods_addr_code() {
        return goods_addr_code;
    }

    public void setGoods_addr_code(String goods_addr_code) {
        this.goods_addr_code = goods_addr_code;
    }

    public String getArrived_country_code() {
        return arrived_country_code;
    }

    public void setArrived_country_code(String arrived_country_code) {
        this.arrived_country_code = arrived_country_code;
    }

    public String getArrived_port_code() {
        return arrived_port_code;
    }

    public void setArrived_port_code(String arrived_port_code) {
        this.arrived_port_code = arrived_port_code;
    }

    public String getPayment_type() {
        return payment_type;
    }

    public void setPayment_type(String payment_type) {
        this.payment_type = payment_type;
    }

    public String getSuifudanValue() {
        return suifudanValue;
    }

    public void setSuifudanValue(String suifudanValue) {
        this.suifudanValue = suifudanValue;
    }

    public String getTrading_country() {
        return trading_country;
    }

    public void setTrading_country(String trading_country) {
        this.trading_country = trading_country;
    }

    public String getTrading_country_code() {
        return trading_country_code;
    }

    public void setTrading_country_code(String trading_country_code) {
        this.trading_country_code = trading_country_code;
    }

    public String getSpecial_relationship_confirm() {
        return special_relationship_confirm;
    }

    public void setSpecial_relationship_confirm(String special_relationship_confirm) {
        this.special_relationship_confirm = special_relationship_confirm;
    }

    public String getPrice_impact_confirm() {
        return price_impact_confirm;
    }

    public void setPrice_impact_confirm(String price_impact_confirm) {
        this.price_impact_confirm = price_impact_confirm;
    }

    public String getPayment_royaltils_confirm() {
        return payment_royaltils_confirm;
    }

    public void setPayment_royaltils_confirm(String payment_royaltils_confirm) {
        this.payment_royaltils_confirm = payment_royaltils_confirm;
    }

    public String getCompany_co_unite() {
        return company_co_unite;
    }

    public void setCompany_co_unite(String company_co_unite) {
        this.company_co_unite = company_co_unite;
    }

    public String getFahuo_company_co_unite() {
        return fahuo_company_co_unite;
    }

    public void setFahuo_company_co_unite(String fahuo_company_co_unite) {
        this.fahuo_company_co_unite = fahuo_company_co_unite;
    }

    public String getShenbao_company_co_unite() {
        return shenbao_company_co_unite;
    }

    public void setShenbao_company_co_unite(String shenbao_company_co_unite) {
        this.shenbao_company_co_unite = shenbao_company_co_unite;
    }

    public DeclarationFree getDeclarationFree() {
        return declarationFree;
    }

    public void setDeclarationFree(DeclarationFree declarationFree) {
        this.declarationFree = declarationFree;
    }

    public List<DiDanAttachment> getDiDans() {
        return diDans;
    }

    public void setDiDans(List<DiDanAttachment> diDans) {
        this.diDans = diDans;
    }

    public String getTradeType() {
        return tradeType;
    }

    public void setTradeType(String tradeType) {
        this.tradeType = tradeType;
    }

    public String getTransport_mode_code() {
        return transport_mode_code;
    }

    public void setTransport_mode_code(String transport_mode_code) {
        this.transport_mode_code = transport_mode_code;
    }

    public Date getPaymentTime() {
        return paymentTime;
    }

    public void setPaymentTime(Date paymentTime) {
        this.paymentTime = paymentTime;
    }

    public static void sortCommidities(Declaration declaration) {
        if (declaration == null || declaration.getCommodities() == null
                || declaration.getCommodities().size() == 0) {
            return;
        }
        // 按照商品序号排序
        (declaration.getCommodities()).sort((o1, o2) -> {
            if (o1 == null)
                return -1;
            if (o2 == null)
                return 1;
            return Integer.valueOf(o1.getIndex_num()) - Integer.valueOf(o2.getIndex_num());
        });
    }

    @Override
    public BaseBusiness fromString(String businessString) {
        return null;
    }

    public RejectContent getRejectContent() {
        List<RejectContent> list = this.getRejectContents();
        if (CollectionUtils.isNotEmpty(list)) {
            list.sort(new Comparator<RejectContent>() {
                @Override
                public int compare(RejectContent o1, RejectContent o2) {
                    if (o1.getRejectDate().after(o2.getRejectDate())) {
                        return -1;
                    } else {
                        return 1;
                    }
                }
            });
            return list.get(0);
        }
        return null;
    }

    @Override
    public int hashCode() {
        int result = sno != null ? sno.hashCode() : 0;
        result = 31 * result + (bl_no != null ? bl_no.hashCode() : 0);
        result = 31 * result + (company_co != null ? company_co.hashCode() : 0);
        result = 31 * result + (fahuo_company_co != null ? fahuo_company_co.hashCode() : 0);
        result = 31 * result + (transport_na != null ? transport_na.hashCode() : 0);
        result = 31 * result + (voyage_no != null ? voyage_no.hashCode() : 0);
        result = 31 * result + (arrived_country != null ? arrived_country.hashCode() : 0);
        result = 31 * result + (arrived_country_code != null ? arrived_country_code.hashCode() : 0);
        result = 31 * result + (arrived_port != null ? arrived_port.hashCode() : 0);
        result = 31 * result + (arrived_port_code != null ? arrived_port_code.hashCode() : 0);
        result = 31 * result + (goods_addr != null ? goods_addr.hashCode() : 0);
        result = 31 * result + (goods_addr_code != null ? goods_addr_code.hashCode() : 0);
        result = 31 * result + (other_goods_addr != null ? other_goods_addr.hashCode() : 0);
        result = 31 * result + (approval_no != null ? approval_no.hashCode() : 0);
        result = 31 * result + (deal_mode != null ? deal_mode.hashCode() : 0);
        result = 31 * result + (goods_count != null ? goods_count.hashCode() : 0);
        result = 31 * result + (goods_package != null ? goods_package.hashCode() : 0);
        result = 31 * result + (net_weight != null ? net_weight.hashCode() : 0);
        result = 31 * result + (remark != null ? remark.hashCode() : 0);
        result = 31 * result + (trade_mode != null ? trade_mode.hashCode() : 0);
        result = 31 * result + (trade_mode_code != null ? trade_mode_code.hashCode() : 0);
        result = 31 * result + (company_name != null ? company_name.hashCode() : 0);
        result = 31 * result + (transport_mode != null ? transport_mode.hashCode() : 0);
        result = 31 * result + (fahuo_company_name != null ? fahuo_company_name.hashCode() : 0);
        result = 31 * result + (levymode != null ? levymode.hashCode() : 0);
        result = 31 * result + (levymode_code != null ? levymode_code.hashCode() : 0);
        result = 31 * result + (lc_type != null ? lc_type.hashCode() : 0);
        result = 31 * result + (contract_no != null ? contract_no.hashCode() : 0);
        result = 31 * result + (gross_weight != null ? gross_weight.hashCode() : 0);
        result = 31 * result + (customs_type != null ? customs_type.hashCode() : 0);
        result = 31 * result + (record_id != null ? record_id.hashCode() : 0);
        result = 31 * result + (export_date != null ? export_date.hashCode() : 0);
        result = 31 * result + (report_date != null ? report_date.hashCode() : 0);
        result = 31 * result + (produce_factory != null ? produce_factory.hashCode() : 0);
        result = 31 * result + (shenbao_company_co != null ? shenbao_company_co.hashCode() : 0);
        result = 31 * result + (shenbao_company_name != null ? shenbao_company_name.hashCode() : 0);
        result = 31 * result + (freight1 != null ? freight1.hashCode() : 0);
        result = 31 * result + (freight2 != null ? freight2.hashCode() : 0);
        result = 31 * result + (freight3 != null ? freight3.hashCode() : 0);
        result = 31 * result + (premium1 != null ? premium1.hashCode() : 0);
        result = 31 * result + (premium2 != null ? premium2.hashCode() : 0);
        result = 31 * result + (premium3 != null ? premium3.hashCode() : 0);
        result = 31 * result + (otherfee1 != null ? otherfee1.hashCode() : 0);
        result = 31 * result + (otherfee2 != null ? otherfee2.hashCode() : 0);
        result = 31 * result + (otherfee3 != null ? otherfee3.hashCode() : 0);
        result = 31 * result + (re_manifest != null ? re_manifest.hashCode() : 0);
        result = 31 * result + (re_record_id != null ? re_record_id.hashCode() : 0);
        result = 31 * result + (re_jianguan != null ? re_jianguan.hashCode() : 0);
        result = 31 * result + (re_yard_id != null ? re_yard_id.hashCode() : 0);
        result = 31 * result + (export_port != null ? export_port.hashCode() : 0);
        result = 31 * result + (export_port_code != null ? export_port_code.hashCode() : 0);
        result = 31 * result + (tex_company != null ? tex_company.hashCode() : 0);
        result = 31 * result + (license_no != null ? license_no.hashCode() : 0);
        result = 31 * result + (suifudan != null ? suifudan.hashCode() : 0);
        result = 31 * result + (suifudanValue != null ? suifudanValue.hashCode() : 0);
        result = 31 * result + (ship_name != null ? ship_name.hashCode() : 0);
        result = 31 * result + (state != null ? state.hashCode() : 0);
        result = 31 * result + (commodities != null ? commodities.hashCode() : 0);
        result = 31 * result + (suiFuDans != null ? suiFuDans.hashCode() : 0);
        result = 31 * result + (declarationInform != null ? declarationInform.hashCode() : 0);
        result = 31 * result + (contractTerms != null ? contractTerms.hashCode() : 0);
        result = 31 * result + (seller != null ? seller.hashCode() : 0);
        result = 31 * result + (seller_address != null ? seller_address.hashCode() : 0);
        result = 31 * result + (seller_phone != null ? seller_phone.hashCode() : 0);
        result = 31 * result + (seller_fax != null ? seller_fax.hashCode() : 0);
        result = 31 * result + (carton != null ? carton.hashCode() : 0);
        result = 31 * result + (buyer != null ? buyer.hashCode() : 0);
        result = 31 * result + (invoice_no != null ? invoice_no.hashCode() : 0);
        result = 31 * result + (is_wood_packaging != null ? is_wood_packaging.hashCode() : 0);
        result = 31 * result + (contract_remark != null ? contract_remark.hashCode() : 0);
        result = 31 * result + (total_money != null ? total_money.hashCode() : 0);
        result = 31 * result + (sum_count != null ? sum_count.hashCode() : 0);
        result = 31 * result + (contract_date != null ? contract_date.hashCode() : 0);
        result = 31 * result + (making_date != null ? making_date.hashCode() : 0);
        result = 31 * result + (singing_place != null ? singing_place.hashCode() : 0);
        result = 31 * result + (concrete_goods_package != null ? concrete_goods_package.hashCode() : 0);
        result = 31 * result + (is_record_info != null ? is_record_info.hashCode() : 0);
        result = 31 * result + (contract_terms_type != null ? contract_terms_type.hashCode() : 0);
        result = 31 * result + (declaration_port != null ? declaration_port.hashCode() : 0);
        result = 31 * result + (declaration_port_code != null ? declaration_port_code.hashCode() : 0);
        result = 31 * result + (trading_country != null ? trading_country.hashCode() : 0);
        result = 31 * result + (trading_country_code != null ? trading_country_code.hashCode() : 0);
        result = 31 * result
                + (special_relationship_confirm != null ? special_relationship_confirm.hashCode() : 0);
        result = 31 * result + (price_impact_confirm != null ? price_impact_confirm.hashCode() : 0);
        result = 31 * result
                + (payment_royaltils_confirm != null ? payment_royaltils_confirm.hashCode() : 0);
        result = 31 * result + (company_co_unite != null ? company_co_unite.hashCode() : 0);
        result = 31 * result + (fahuo_company_co_unite != null ? fahuo_company_co_unite.hashCode() : 0);
        result =
                31 * result + (shenbao_company_co_unite != null ? shenbao_company_co_unite.hashCode() : 0);
        result = 31 * result + (custom_time != null ? custom_time.hashCode() : 0);
        result = 31 * result + (custom_status != null ? custom_status.hashCode() : 0);
        result = 31 * result + (check_time != null ? check_time.hashCode() : 0);
        result = 31 * result + (check_status != null ? check_status.hashCode() : 0);
        result = 31 * result + (containerInfo != null ? containerInfo.hashCode() : 0);
        result = 31 * result + (uploadDiDan != null ? uploadDiDan.hashCode() : 0);
        result = 31 * result + (container_no != null ? container_no.hashCode() : 0);
        result = 31 * result + (container_no_show != null ? container_no_show.hashCode() : 0);
        result = 31 * result + (so != null ? so.hashCode() : 0);
        result = 31 * result + (declarationFreeDetail != null ? declarationFreeDetail.hashCode() : 0);
        result = 31 * result + (declaration_free != null ? declaration_free.hashCode() : 0);
        result = 31 * result + (container_num != null ? container_num.hashCode() : 0);
        result = 31 * result + (pay_id != null ? pay_id.hashCode() : 0);
        result = 31 * result + (workNo != null ? workNo.hashCode() : 0);
        result = 31 * result + (payment_type != null ? payment_type.hashCode() : 0);
        result = 31 * result + (declaration_type != null ? declaration_type.hashCode() : 0);
        result = 31 * result + (evaluation != null ? evaluation.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Declaration{" + "sno='" + sno + '\'' + ", bl_no='" + bl_no + '\'' + ", company_co='"
                + company_co + '\'' + ", fahuo_company_co='" + fahuo_company_co + '\'' + ", transport_na='"
                + transport_na + '\'' + ", voyage_no='" + voyage_no + '\'' + ", arrived_country='"
                + arrived_country + '\'' + ", arrived_country_code='" + arrived_country_code + '\''
                + ", arrived_port='" + arrived_port + '\'' + ", arrived_port_code='" + arrived_port_code
                + '\'' + ", goods_addr='" + goods_addr + '\'' + ", goods_addr_code='" + goods_addr_code
                + '\'' + ", other_goods_addr='" + other_goods_addr + '\'' + ", approval_no='" + approval_no
                + '\'' + ", deal_mode='" + deal_mode + '\'' + ", goods_count='" + goods_count + '\''
                + ", goods_package='" + goods_package + '\'' + ", net_weight='" + net_weight + '\''
                + ", remark='" + remark + '\'' + ", trade_mode='" + trade_mode + '\''
                + ", trade_mode_code='" + trade_mode_code + '\'' + ", company_name='" + company_name + '\''
                + ", transport_mode='" + transport_mode + '\'' + ", fahuo_company_name='"
                + fahuo_company_name + '\'' + ", levymode='" + levymode + '\'' + ", levymode_code='"
                + levymode_code + '\'' + ", lc_type='" + lc_type + '\'' + ", contract_no='" + contract_no
                + '\'' + ", gross_weight='" + gross_weight + '\'' + ", customs_type='" + customs_type + '\''
                + ", record_id='" + record_id + '\'' + ", export_date=" + export_date + ", report_date="
                + report_date + ", produce_factory='" + produce_factory + '\'' + ", shenbao_company_co='"
                + shenbao_company_co + '\'' + ", shenbao_company_name='" + shenbao_company_name + '\''
                + ", freight1='" + freight1 + '\'' + ", freight2='" + freight2 + '\'' + ", freight3='"
                + freight3 + '\'' + ", premium1='" + premium1 + '\'' + ", premium2='" + premium2 + '\''
                + ", premium3='" + premium3 + '\'' + ", otherfee1='" + otherfee1 + '\'' + ", otherfee2='"
                + otherfee2 + '\'' + ", otherfee3='" + otherfee3 + '\'' + ", re_manifest='" + re_manifest
                + '\'' + ", re_record_id='" + re_record_id + '\'' + ", re_jianguan='" + re_jianguan + '\''
                + ", re_yard_id='" + re_yard_id + '\'' + ", export_port='" + export_port + '\''
                + ", export_port_code='" + export_port_code + '\'' + ", tex_company='" + tex_company + '\''
                + ", license_no='" + license_no + '\'' + ", suifudan='" + suifudan + '\''
                + ", suifudanValue='" + suifudanValue + '\'' + ", ship_name='" + ship_name + '\''
                + ", state='" + state + '\'' + ", commodities=" + commodities + ", suiFuDans=" + suiFuDans
                + ", declarationInform=" + declarationInform + ", contractTerms=" + contractTerms
                + ", seller='" + seller + '\'' + ", seller_address='" + seller_address + '\''
                + ", seller_phone='" + seller_phone + '\'' + ", seller_fax='" + seller_fax + '\''
                + ", carton='" + carton + '\'' + ", buyer='" + buyer + '\'' + ", invoice_no='" + invoice_no
                + '\'' + ", is_wood_packaging='" + is_wood_packaging + '\'' + ", contract_remark='"
                + contract_remark + '\'' + ", total_money='" + total_money + '\'' + ", sum_count='"
                + sum_count + '\'' + ", contract_date=" + contract_date + ", making_date=" + making_date
                + ", singing_place='" + singing_place + '\'' + ", concrete_goods_package='"
                + concrete_goods_package + '\'' + ", is_record_info='" + is_record_info + '\''
                + ", contract_terms_type='" + contract_terms_type + '\'' + ", declaration_port='"
                + declaration_port + '\'' + ", declaration_port_code='" + declaration_port_code + '\''
                + ", trading_country='" + trading_country + '\'' + ", trading_country_code='"
                + trading_country_code + '\'' + ", special_relationship_confirm='"
                + special_relationship_confirm + '\'' + ", price_impact_confirm='" + price_impact_confirm
                + '\'' + ", payment_royaltils_confirm='" + payment_royaltils_confirm + '\''
                + ", company_co_unite='" + company_co_unite + '\'' + ", fahuo_company_co_unite='"
                + fahuo_company_co_unite + '\'' + ", shenbao_company_co_unite='" + shenbao_company_co_unite
                + '\'' + ", custom_time=" + custom_time + ", custom_status='" + custom_status + '\''
                + ", check_time=" + check_time + ", check_status='" + check_status + '\''
                + ", containerInfo=" + containerInfo + ", uploadDiDan=" + uploadDiDan + ", container_no='"
                + container_no + '\'' + ", container_no_show='" + container_no_show + '\'' + ", so='" + so
                + '\'' + ", declarationFreeDetail=" + declarationFreeDetail + ", declaration_free="
                + declaration_free + ", container_num='" + container_num + '\'' + ", pay_id='" + pay_id
                + '\'' + ", work_no='" + workNo + '\'' + ", payment_type='" + payment_type + '\''
                + ", declaration_type='" + declaration_type + '\'' + ", evaluation=" + evaluation + '}';
    }

    public String getData_type() {
        return data_type;
    }

    public void setData_type(String data_type) {
        this.data_type = data_type;
    }

    public String getShip_code() {
        return ship_code;
    }

    public void setShip_code(String ship_code) {
        this.ship_code = ship_code;
    }

    public String getActionChain() {
        return actionChain;
    }

    public void setActionChain(String actionChain) {
        this.actionChain = actionChain;
    }

    public void clearActionChain() {
        this.actionChain = null;
    }

    public enum ChainModel {
        copy, userExcl, userModel, save, submit
    }

    public String getDeclaStatus() {
        return declaStatus;
    }

    public void setDeclaStatus(String declaStatus) {
        this.declaStatus = declaStatus;
    }


    public void setActionChain(ChainModel chainModel, boolean isVersion3) {
        if (StringUtils.isEmpty(actionChain)) {
            actionChain = "";
        }
        if (isVersion3) {
            switch (chainModel) {
                case copy:
                    actionChain += "-C3";
                    break;
                case userExcl:
                    actionChain += "-E3";
                    break;
                case userModel:
                    actionChain += "-M3";
                    break;
                case save:
                    actionChain += "-s3";
                    break;
                case submit:
                    actionChain += "-S3";

            }
        } else {
            switch (chainModel) {
                case copy:
                    actionChain += "-C2";
                    break;
                case userModel:
                    actionChain += "-M2";
                    break;
                case save:
                    actionChain += "-s2";
                    break;
                case submit:
                    actionChain += "-S2";

            }
        }
        if (actionChain.indexOf("-") == 0) {
            actionChain = actionChain.replaceFirst("-", "");
        }
    }

    public String getFreight1Code() {
        return freight1Code;
    }

    public void setFreight1Code(String freight1Code) {
        this.freight1Code = freight1Code;
    }

    public String getFreight3Code() {
        return freight3Code;
    }

    public void setFreight3Code(String freight3Code) {
        this.freight3Code = freight3Code;
    }

    public String getPremium1Code() {
        return premium1Code;
    }

    public void setPremium1Code(String premium1Code) {
        this.premium1Code = premium1Code;
    }

    public String getPremium3Code() {
        return premium3Code;
    }

    public void setPremium3Code(String premium3Code) {
        this.premium3Code = premium3Code;
    }

    public String getOtherfee1Code() {
        return otherfee1Code;
    }

    public void setOtherfee1Code(String otherfee1Code) {
        this.otherfee1Code = otherfee1Code;
    }

    public String getOtherfee3Code() {
        return otherfee3Code;
    }

    public void setOtherfee3Code(String otherfee3Code) {
        this.otherfee3Code = otherfee3Code;
    }

    public String getLockStatus() {
        return lockStatus;
    }

    public void setLockStatus(String lockStatus) {
        this.lockStatus = lockStatus;
    }

    public String getGoods_item_num() {
        return goods_item_num;
    }

    public void setGoods_item_num(String goods_item_num) {
        this.goods_item_num = goods_item_num;
    }

    public String getConfirmType() {
        return confirmType;
    }

    public void setConfirmType(String confirmType) {
        this.confirmType = confirmType;
    }

    public Date getConfirmTypeTime() {
        return confirmTypeTime;
    }

    public void setConfirmTypeTime(Date confirmTypeTime) {
        this.confirmTypeTime = confirmTypeTime;
    }
}
